﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.IO;
using System.Collections;
using System.Data;


public partial class CMS_Admin_Check : System.Web.UI.Page
{
    Usas.Model.Cms.cmsArticle artm = new Usas.Model.Cms.cmsArticle();
    Usas.Common.Cms.Role ro = new Usas.Common.Cms.Role();
    Usas.Common.Cms.CurrentInfo cinfo = new Usas.Common.Cms.CurrentInfo();
    Usas.Common.Cms.FileControl fc = new Usas.Common.Cms.FileControl();
    Usas.BLL.Cms.cmsArticle art = new Usas.BLL.Cms.cmsArticle();
    Usas.BLL.Cms.UsasDB udb = new Usas.BLL.Cms.UsasDB();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request["IsDel"] != null)
            {
                Bind(true);
            }
            else
            {
                if (Request["check"].ToString() == ro.GetMd5Str32(Request["id"].ToString() + "check"))
                {
                    Bind(false);
                }
                else
                {
                    Response.Write("<h1>非法的访问</h1>");
                    ContentDiv.Visible = false;
                }
            }

            lbtnRv.Visible = false;
        }
    }

    private void Bind(bool IsDel)
    {
        try
        {

            object artid = Request["id"];
            if (artid.ToString() != "")
            {
                artm = art.GetModel(Convert.ToInt32(artid));

                RouterBar1.IntiBarNoHTML(CMS_Control_RouterBar.ShowMode.Article, Convert.ToInt32(artm.ArtId), new ArrayList());

                switch (artm.PublishStatus)
                {
                    case 0:

                        break;
                    case 1:
                        ContentDiv.InnerHtml = "<b>已审核</b>";
                        return;
                        break;
                    case 2:
                        Save.Visible = true;
                        tt.Text = "内容审核";
                        break;
                    case 3:
                        Button1.Visible = false;
                        Save.Visible = false;
                        go_to_edit.Visible = false;
                        tt.Text = "回收站明细";
                        break;
                }


                if (Request["eid"] != null)
                {
                    Session["EmpId"] = Request["eid"].ToString();
                    Session["EmpName"] = Server.UrlDecode(Request["ename"]);
                    //SortedList std = new SortedList();
                    //std.Add("SuperAdminGroup", true);
                    //Session["CmsGroup"] = std;

                }

                lblTname.Text = artm.ArtTopic;

                hits.Text = "阅览数：" + artm.hits.ToString() + "　｜　";



                if (artm.Writer == 0)
                {
                    writer.Visible = false;
                }
                else
                {
                    DataSet zuozheds = udb.SelEmployees("EmployeeId=" + artm.Writer);
                    writer.Text = zuozheds != null && zuozheds.Tables[0].Rows.Count > 0 ? "作者：" + zuozheds.Tables[0].Rows[0]["EmpName"].ToString() + "　｜　" : "";
                }

                if (artm.Modify == 0)
                {
                    modfiy.Visible = false;
                }
                else
                {
                    DataSet zuozheds = udb.SelEmployees("EmployeeId=" + artm.Writer);
                    modfiy.Text = zuozheds != null && zuozheds.Tables[0].Rows.Count > 0 ? "文章录入：" + zuozheds.Tables[0].Rows[0]["EmpName"].ToString() + "　｜　" : "";
                }

                if (artm.ModfiyTime.ToString() == "")
                {
                    modfiytime.Visible = false;
                }
                else
                {
                    modfiytime.Text = "更新时间：" + artm.ModfiyTime.Value.ToString("yyyy-MM-dd") + "　｜　";
                }



                if (artm.ArtSummary.Trim().Length > 0)
                {
                    sum.Visible = true;
                    sumcontent.InnerText = "内容摘要：" + artm.ArtSummary.Trim();
                }
                else
                {
                    sum.Visible = false;
                }

                if (artm.ArtKeys.Trim().Length > 0)
                {
                    artkey.Visible = true;
                    artkey.InnerHtml = "关键字：<span style='font-weight:bold;color:red'>" + artm.ArtKeys.Trim() + "</span>";
                }
                else
                {
                    artkey.Visible = false;
                }

                Version1.GetValue(artm.ArtId.ToString(), true);

                string temppath = ConfigurationSettings.AppSettings["UsasInformationPath"];
                if (temppath.IndexOf(":") == -1)
                {
                    temppath = MapPath(temppath + "CMSUpLoadFiles\\" + artm.ArtDirectory + "\\" + artm.ArtFileName);
                }
                else
                {
                    temppath += "CMSUpLoadFiles\\" + artm.ArtDirectory + "\\" + artm.ArtFileName;
                }

                //保密
                bool adit = false;
                adit = (adit ? adit : !artm.Audit);

                if (artm.ArtFormat != 2)
                {
                    //lb.Text = "点击此处";
                    FileInfo fn = new System.IO.FileInfo(temppath);

                    fc.OnlySee(pn, true, artm.ArtDirectory.Replace("\\", "/") + "/" + artm.ArtFileName, Path.GetExtension(temppath), adit);

                    FileContent.Visible = false;
                    Plus.Visible = true;
                }
                else
                {
                    if (File.Exists(temppath))
                    {
                        string msg = File.ReadAllText(temppath, System.Text.Encoding.GetEncoding("UTF-8")).ToString();
                        FileContent.InnerHtml = msg;
                        // lb.Visible = false;
                        Plus.Visible = false;
                    }
                    else
                    {
                        FileContent.Visible = false;
                        // lb.Visible = false;
                        Plus.Visible = false;
                    }
                }

                if (artm.CanView)
                {
                    Save.Width = Unit.Pixel(300);
                    Save.Text = "该内容已删除，“审核通过”放入回收站";
                    Save.Attributes.Add("onclick", "return confirm('该内容已删除，审核通过放入回收站')");
                }
                else
                {
                    Save.Text = "审核通过";
                }


                lbtnRv.Attributes.Add("onclick", "window.open('../ChatList.aspx?Id=" + Request["id"].ToString() + "&IsUrl=" +
                ro.GetMd5Str(Request["id"].ToString() + "IsUrlTrue") + "&topic=" + Server.UrlEncode(lblTname.Text) + "&check=" +
                ro.GetMd5Str(Request["id"].ToString() + "checkTrue") + "','newwindow',' height=800, width=850, toolbar=no, menubar=no, scrollbars=yes,status=no,top=100,left=300');return false");
                //ReViewBox1.ChatBoxInit(Convert.ToInt32(artm.ArtId), artm.ArtTopic, check);

            }
        }
        catch
        {
            ContentDiv.Visible = false;
            //ViewControlBar1.IntiControl(false, "", "", "");
        }
    }




    protected void Save_Click(object sender, EventArgs e)
    {
        object artid = Request["id"];

        artm = art.GetModel(Convert.ToInt32(artid));

      
        artm.PublishStatus = 1;

        art.Update(artm);

        ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('审核通过！');window.close()", true);

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        object artid = Request["id"];

        artm = art.GetModel(Convert.ToInt32(artid));


        artm.CanView = true;
        artm.PublishStatus = 3;
        
        art.Update(artm);

        ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('执行成功！');window.close()", true);
    }
    protected void go_to_edit_Click(object sender, EventArgs e)
    {
        Response.Redirect("ViewContent.aspx?id=" + Request["id"].ToString() + "&type=a&check=" + ro.GetMd5Str32(Request["id"].ToString() + "check"));
    }
}
